package cn.jekun.shop.app.action;

import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import net.sf.json.JSONObject;
import cn.jekun.component.base.bean.ErrorMsg;
import cn.jekun.component.base.exceptions.BusinessException;
import cn.jekun.component.base.utils.SqlUtis;
import cn.jekun.component.core.Constants;
import cn.jekun.component.core.bean.gen.ErpSalePrice;
import cn.jekun.component.core.bean.gen.McMember;
import cn.jekun.component.core.service.gen.ErpSalePriceService;
import cn.jekun.component.core.service.gen.McMemberService;
import cn.jekun.shop.common.service.ShopService;
/**
 * 商家信息
 * @author twj
 *
 */
@SuppressWarnings("serial")
public class ShopAction extends AppBaseAction{
	private static Logger logger=Logger.getLogger(ShopAction.class);
	@Resource(name = ShopService.BEAN_NAME)
	protected ShopService shopService;
	@Resource(name = McMemberService.BEAN_NAME)
	McMemberService memberService;
	private String shopName ;
	private String tempShopId;
	private String userId;
	
	@Resource(name = ErpSalePriceService.BEAN_NAME)
	private ErpSalePriceService erpSalePriceService;
	
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getShopName() {
		return shopName;
	}
	public void setShopName(String shopName) {
		this.shopName = shopName;
	}
	public String getTempShopId() {
		return tempShopId;
	}
	public void setTempShopId(String tempShopId) {
		this.tempShopId = tempShopId;
	}
	/**
	 * 首页推荐商家列表
	 * @return
	 */
	public String recommendShopList(){
		JSONObject jsonObject = null;
		try{
			String lng = this.request.getParameter("lng");//经度
			String lat = this.request.getParameter("lat");//纬度
			String currentCityId = this.request.getParameter("currentCityId");//当前城市编码(附近)
			this.validateSign(lng,lat,currentCityId);
			jsonObject = shopService.recommendShopList(lng,lat,currentCityId);
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	
	
	
	/**
	 * 商家列表
	 * @return
	 */
	public String shopList(){
		JSONObject jsonObject = null;
		try{
		String pageSize = this.request.getParameter("pageSize");//页大小
		String currentPage = this.request.getParameter("currentPage");//当前页
		String typeId = this.request.getParameter("typeId");//商家类型编码
		String lng = this.request.getParameter("lng");//经度
		String lat = this.request.getParameter("lat");//纬度
		String cityId = this.request.getParameter("cityId");//已开通城市编码(首页)
		String shopName = this.request.getParameter("shopName");//商家名称
		String speTypeId = this.request.getParameter("speTypeId");//特色
		String sort = this.request.getParameter("sort");//排序字段   0：最近   1：起送金额最少    2：默认排序
		String shopId = this.request.getParameter("shopId");//商家编码
		String distance = this.request.getParameter("distance");//距离
		String currentCityId = this.request.getParameter("currentCityId");//当前城市编码(附近)
		this.validateSign(pageSize,currentPage,typeId,lng,lat,cityId,shopName,speTypeId,sort,shopId);
		jsonObject = shopService.queryList(pageSize,currentPage,typeId,lng,lat,cityId,shopName,speTypeId,sort,shopId,distance,currentCityId);
		System.out.println("jsonObject ====================================== " + jsonObject);
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
		
	}
	/**
	 * 商家商品分类(app商家商品分类，或商品管理的商品分类，通过customFlag区分)
	 * @return
	 */
	public String shopGoodsType(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");//商家编码
			String parentId = this.request.getParameter("parentId");//商家商品类型表中的父分类代码
			String customFlag = this.request.getParameter("customFlag");//商品管理-商品分类使用。不过滤没有商品的分类
			this.validateSign(shopId,parentId);
			
			//BOX-825
//			String model = this.request.getParameter("model");
//			if (StringUtils.isNotBlank(model)) {//TODO 删除这个判断
//				jsonObject = shopService.shopGoodsType(parentId, shopId);
//			}else{
				if (StringUtils.isNotBlank(customFlag)) {//商品管理-本店商品分类
					jsonObject = shopService.getShopGoodsType(parentId, shopId);
				}else{//商品列表-商品分类
					jsonObject = shopService.shopGoodsType(parentId, shopId);
				}
//			}
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 关注商家
	 * @return
	 */
	public String concernShop(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			this.validateLoginApp();
			this.validateSign(getLoginSign(),getUserId(),shopId);
			jsonObject = shopService.concernShop(getUserId(),shopId);
			this.logService.addMallLog(this.getUserId(), 
					this.getBrowser(), this.getIp(), "关注商家成功"+shopId+"，来源:mobile");//记录操作日志

		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
			this.logService.addMallLog(this.getUserId(), 
					this.getBrowser(), this.getIp(), "关注商家失败，原因:"+jsonObject.get("message")+",来源:mobile");//记录操作日志

		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 取消关注商家
	 * @return
	 */
	public String cancleConcernShop(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			this.validateLoginApp();
			this.validateSign(getLoginSign(),getUserId(),shopId);
			jsonObject = shopService.cancleConcernShop(getUserId(),shopId);
			this.logService.addMallLog(this.getUserId(), 
					this.getBrowser(), this.getIp(), "取消关注商家"+shopId+"成功");//记录操作日志

		} catch (BusinessException e) {
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
			this.logService.addMallLog(this.getUserId(), 
					this.getBrowser(), this.getIp(), "取消关注商家失败，原因:"+jsonObject.get("message")+",操作来源:"+this.getUserId());//记录操作日志

		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	
	/*
	 * 通过shopId获取商家信息
	 */
	public String getShopInfo(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			jsonObject = this.shopService.getShopIndo(shopId);
			
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		if(jsonObject.get("code").equals("1")){
			shopName = jsonObject.getString("shopName").toString();
			tempShopId = jsonObject.getString("shopId").toString();
			userId = "";
			
		}else{
			shopName = "云便利商店";
			tempShopId = "";
			userId = "";
		}
		return "/reg/reg.jsp";
	}
	/*
	 * 通过shopId获取商家信息 _wifi支持
	 */
	public String getWifiShopInfo(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			jsonObject = this.shopService.getShopIndo(shopId);
			
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		if(jsonObject.get("code").equals("1")){
			shopName = jsonObject.getString("shopName").toString();
			tempShopId = jsonObject.getString("shopId").toString();
			
		}else{
			shopName = "云便利商店";
			tempShopId = "";
		}
		return "/wifi/reg.jsp";
	}
	
	/**
	 * 
	* @Title: switchShopBusinessStatus
	* @Description: 切换商家的状态
	* @param @return    设定文件
	* @return String    返回类型
	* @throws
	 */
	public String switchShopBusinessStatus(){
		JSONObject jsonObject = null;
		try{
			logger.info("========================ShopAction switchShopBusinessStatus============================");
			String shopId = this.request.getParameter("shopId");
			String userId = this.request.getParameter("userId");
			String businessStatus = this.request.getParameter("businessStatus");
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),shopId,userId,businessStatus);
			logger.info("=========================参数shopId = "+shopId+":businessStatus="+businessStatus+"==========================================================");
		    jsonObject = this.shopService.switchBusinessStatus(shopId, businessStatus);
		    
		    this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "手机商家"+shopId+"切换营业模式"+businessStatus);//记录操作日志
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/***
	 * 
	* @Title: showShopIntroduction
	* @Description:   商家简介
	* @param @return    设定文件
	* @return String    返回类型
	* @throws
	 */
	public String showShopIntroduction(){
		JSONObject  jsonObject = null;
		try{
			logger.info("==================================ShopAction showShopIntroduction=============================================");
			String shopId = this.request.getParameter("shopId");
			this.validateSign(shopId);
            logger.info("===================================请求参数：shopId = "+shopId+"=============================================================");
			jsonObject = this.shopService.getShopIntroduct(shopId);
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 *  修改并保存商家的简介
	 *  @return
	 *
	 */
	public String modifyShopIntroduction(){
		JSONObject  jsonObject = null;
		try{
			logger.info("==================================ShopAction modifShopIntroduction begin=============================================");
			String shopId = this.request.getParameter("shopId");
			String userId = this.request.getParameter("userId");
			String introduction = this.request.getParameter("introduction");
			
			String sourceTxt = "shopId="+shopId+":introduction="+introduction;
			logger.info("===================================请终端app上传的参数： "+sourceTxt+"=============================================================");
		    //登录签名验证			
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId,shopId);
            
			jsonObject = this.shopService.modifyShopIntroduction(shopId,introduction);
			
			logger.info("==================================ShopAction modifShopIntroduction end=============================================");
			this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "手机商家"+shopId+"修改简介");//记录操作日志
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
    /**
     * 
    * @Title: shopShowBusinessStatus
    * @Description: 初始化商家的营业状态
    * @param @return    设定文件
    * @return String    返回类型
    * @throws
     */
	public String shopShowBusinessStatus(){
		JSONObject jsonObject = null;
		try{
			logger.info("=============================ShopAction shopShowBusinessStatus====================================");
			String shopId = this.request.getParameter("shopId"); 
			this.validateSign(shopId);
			logger.info("=============================参数："+shopId+"====================================");
			jsonObject = this.shopService.getShopIndoBusinesStatus(shopId);
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 * 获取商家的基本信息
	 *  @return
	 *
	 */
	public String getShopInfoByShopId(){
		JSONObject jsonObject = null;
		try{
			logger.info("=====================================ShopAction getShopInfoByShopId begin==============================================");
			String shopId = this.request.getParameter("shopId");
			String userId = this.request.getParameter("userId");

			String sourceTxt = "shopId="+shopId+":userId="+userId;
			logger.info("=========================================终端上送的参数："+sourceTxt+"======================================================");
//			登录和签名验证
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId,shopId);
			
			jsonObject = this.shopService.getShopInfoByShopId(shopId);
			
            logger.info("=======================jsonObject="+jsonObject);
			logger.info("==========================================ShopAction getShopInfoByShopId end=========================================");
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	
	
	
	/**
	 * 根据搜索地址查询商检基本信息
	 * @return
	 */
	public String getShopInfoByAddress()
	{
		JSONObject jsonObject = null;
		try{
			String address = this.request.getParameter("address");
			
			String sourceTxt = "address="+address;
			
			jsonObject = this.shopService.getShopInfoByAddress(address);
			}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
			
	}
	
	
	
	/**
	 * 获取商家类型列表
	 *  @return
	 *
	 */
	public String getShopType(){
		JSONObject jsonObject = null;
		try{
			logger.info("=====================================ShopAction getShopType begin==============================================");
			String userId = this.request.getParameter("userId");
			//签名验证
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId);
			
			jsonObject = this.shopService.getShopType();
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 * 修改商家的基本信息
	 *  @return
	 *
	 */
	public String updateShopMessage(){
		JSONObject jsonObject = null;
		try{
			logger.info("============================ShopAction updateShopMessage begin==========================");
			   String logoUrl = this.request.getParameter("logoUrl"); //logo图片
		       String shopName = this.request.getParameter("shopName"); //简称
		       String comName = this.request.getParameter("comName"); //全称
		       String shopTypeId = this.request.getParameter("shopTypeId"); //商家类型
		       String phone = this.request.getParameter("phone"); //固定电话
	           String mobile = this.request.getParameter("mobile"); //手机号码
	           String contact = this.request.getParameter("contact"); //联系人
	           String businessHours = this.request.getParameter("businessHours"); //营业时间
	           String minAmount = this.request.getParameter("minAmount"); //起送金额
	           String range = this.request.getParameter("range"); //配送范围
	           String address = this.request.getParameter("address");//地址
	           String street = this.request.getParameter("street"); //详细地址
	           String shopId = this.request.getParameter("shopId");
	           String userId = this.request.getParameter("userId");
	           String provinceId = this.request.getParameter("provinceId");//省份代码
	           String cityId = this.request.getParameter("cityId"); //城市代码
	           String regionId = this.request.getParameter("regionId"); //区域代码
	           String longItude = this.request.getParameter("longItude"); //经度
	           String latItude = this.request.getParameter("latItude"); //纬度
	           String isZiti = this.request.getParameter("isZiti");//是否自提
	           String deliveryAmount = this.request.getParameter("deliveryAmount");//配送费
	           
	           String sourceTxt = "logoUrl="+logoUrl+":shopName="+shopName+":comName="+comName+":shopTypeId="+shopTypeId+":phone="+phone+":mobile="+mobile+
	        		               ":contact="+contact+":businessHourse="+businessHours+":minAmount="+minAmount+":range="+range+":address="+address+":street="
	        		                +street+":shopId="+shopId+"userId="+userId+"provinceId="+provinceId+"cityId="+cityId+":regionId="+regionId+"longItude="+logoUrl
	        		                +"latiItude="+latItude+"isZiti"+isZiti+"deliveryAmount="+deliveryAmount;
	           logger.info("===================================终端app上传的参数为："+sourceTxt+"==========================================");
	           //登录验证和签名
	           this.validateLoginApp();
	           this.validateSign(this.getLoginSign(),userId,shopId,logoUrl,shopName,comName,shopTypeId,phone,mobile,contact,businessHours,
	        		   minAmount,range,address,street,provinceId,cityId,regionId,longItude,latItude,isZiti,deliveryAmount);
	           
	           jsonObject = this.shopService.updateShopMessage(shopId, logoUrl, shopName, comName, shopTypeId, phone, mobile, contact, businessHours, minAmount, range, address, street, provinceId, cityId, regionId, longItude, latItude,isZiti,deliveryAmount);
	           logger.info("==================================ShopAction updateShopMessage begin===========================================");
	           this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "手机商家"+shopId+"修改基本信息");//记录操作日志
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 *  获取商家的相册
	 *  @return
	 *
	 */
	public String getShopPic(){
		JSONObject jsonObject = null;
		try{
			logger.info("============================ShopAction getShopPic begin==========================");
			String userId = this.request.getParameter("userId");
			String shopId = this.request.getParameter("shopId");
			
			String sourceTxt = "userId ="+userId+":shopId="+shopId;
			logger.info("==========================终端app上传的参数："+sourceTxt+"======================================");
            //登录签名验证			
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId,shopId);
			
			jsonObject = this.shopService.getShopPics(shopId);
			logger.info("============================ShopAction getShopPic end==========================");
			
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 * 添加商家图片信息
	 *  @return
	 *
	 */
	public String addShopPic(){
		JSONObject jsonObject = null;
		try{
			logger.info("============================ShopAction modifyOrDelShopPic begin==========================");
			String userId = this.request.getParameter("userId");
			String shopId = this.request.getParameter("shopId");
			String shopPicUrl = this.request.getParameter("shopPicUrl");
			
			String sourceTxt = "userId ="+userId+":shopId="+shopId+":shopPicUrl="+shopPicUrl;
			logger.info("==========================终端app上传的参数："+sourceTxt+"======================================");
//			登录验证签名
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId,shopId,shopPicUrl);
			
			jsonObject = this.shopService.addShopPic(shopId,userId,shopPicUrl);
			
			logger.info("============================ShopAction getShopPic end==========================");
			
			this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "手机商家"+shopId+"增加商家相册图片");//记录操作日志
			
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 *  删除商家图片
	 *  @return
	 *
	 */
	public String delShopPic(){
		JSONObject jsonObject = null;
		try{
			logger.info("============================ShopAction delShopPic begin==========================");
			String userId = this.request.getParameter("userId");
			String shopId = this.request.getParameter("shopId");
			String shopPicId = this.request.getParameter("shopPicId");
			
			String sourceTxt = "userId ="+userId+":shopId="+shopId+":shopPicId="+shopPicId;
			logger.info("==========================终端app上传的参数："+sourceTxt+"======================================");
			
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId,shopId,shopPicId);
			
			jsonObject = this.shopService.delShopPic(shopPicId);
			
			logger.info("============================ShopAction delShopPic end==========================");
			
			this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "手机商家"+shopId+"删除商家相册图片");//记录操作日志
			
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 查询商家公告和经营状态
	 * @return
	 */
	public String showShopNoticeAndBusinessStatus(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			this.validateSign(shopId);
			jsonObject = this.shopService.showShopNoticeAndBusinessStatus(shopId);
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 店铺详情
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String queryShopMessage(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			String userId = this.request.getParameter("userId");
			this.validateSign(shopId);
			jsonObject = this.shopService.queryShopMessage(shopId,userId);
			if(StringUtils.isNotBlank(userId) && jsonObject.get("shop") != null){
				formMap.put(McMember.COL_SHOP_ID, shopId);
				formMap.put(McMember.COL_USER_ID, userId);
				formMap.put(McMember.COL_CONCERN, "1");
				SqlUtis.prepareSql(formMap, 
						SqlUtis.getSQL(formMap, McMember.COL_SHOP_ID,Types.VARCHAR,SqlUtis.EQ),
						SqlUtis.getSQL(formMap, McMember.COL_CONCERN,Types.VARCHAR,SqlUtis.EQ)
						,SqlUtis.getSQL(formMap, McMember.COL_USER_ID,Types.VARCHAR,SqlUtis.EQ));
				JSONObject json = (JSONObject)jsonObject.get("shop");
				if(this.memberService.exists(formMap)){
					json.put("memberflag", "1");
				}else{
					json.put("memberflag", "0");
				}
			}
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	
	/**
	 * 开店获取商家分类
	 * @return
	 */
	public String getOpenShopType(){
		JSONObject jsonObject = null;
		try{
			String parentId=this.request.getParameter("parentId");
			jsonObject = this.shopService.getOpenShopType(parentId);
			//返回开店支付服务
			
			//开店服务的价格
			Map saleMap = new HashMap();
			saleMap.put(ErpSalePrice.COL_MERCHANDISE_ID, Constants.ERP_SHOP_FUWU.ONLIE_PAYMENT);
			SqlUtis.prepareSql(saleMap,SqlUtis.getSQL(saleMap, ErpSalePrice.COL_MERCHANDISE_ID,Types.VARCHAR,SqlUtis.EQ));
			ErpSalePrice erpSalePrice = erpSalePriceService.one(saleMap);
			if (erpSalePrice != null && erpSalePrice.getPrice()!=null ) {
				jsonObject.put("price", erpSalePrice.getPrice());
			}else {
				jsonObject.put("price", "0");
			}
			
			
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 开店保存商家信息
	 * @return
	 */
	public String openShop(){
		JSONObject jsonObject = null;
		try{
			String shopName = request.getParameter("shopName");//商店名称
			String identityNo = request.getParameter("identityNo");//身份证号码
			String identityImage1 = request.getParameter("identityImage1");//身份证图片A
			String identityImage2 = request.getParameter("identityImage2");//身份证图片B
			String identityImage3 = request.getParameter("identityImage3");//身份证图片C
			String provinceId = request.getParameter("provinceId");//省份代码
			String cityId = request.getParameter("cityId");//城市代码
			String regionId = request.getParameter("regionId");//区域代码
			String address = request.getParameter("address");//详细地址
			String street = request.getParameter("street"); //街道
			String longitude = request.getParameter("longitude");//经度
			String latitude = request.getParameter("latitude");//纬度
			String phone = request.getParameter("phone");//联系电话
			String mobile = request.getParameter("mobile");//联系手机
			String psw = request.getParameter("psw");//商家支付密码
			String shopTypeId = request.getParameter("shopTypeId");//商家支付密码
			String email = request.getParameter("email");//开店邮箱
			String range = request.getParameter("range");//配送范围
			
			String certificate1 = request.getParameter("certificate1");//证件1
			String certificate2 = request.getParameter("certificate2");//证件2
			String certificate3 = request.getParameter("certificate3");//证件3
			String certificate4 = request.getParameter("certificate4");//证件4
			String certificate5 = request.getParameter("certificate5");//证件5
			
			
			this.validateLoginApp();
			this.validateSign(shopName,identityNo);
			
			jsonObject = this.shopService.openShop(shopName,identityNo,identityImage1,identityImage2,identityImage3,
					provinceId,cityId,regionId,address,street,longitude,latitude,phone,mobile,psw,
					certificate1,certificate2,certificate3,certificate4,certificate5,getUserId(),shopTypeId,email,range);
			
			this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "手机商家开店");//记录操作日志
			
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 修改营业状态类型
	 * @return
	 */
	public String updateBusinessStatusType(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			String userId = this.request.getParameter("userId");
			String businessStatusType = this.request.getParameter("businessStatusType");
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),shopId,userId,businessStatusType);
			 jsonObject = this.shopService.switchBusinessStatusType(shopId, businessStatusType);
			 
			 this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "手机商家"+shopId+"修改营业状态"+businessStatusType);//记录操作日志
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
		
	}
  }
